package IOpearation;

import Book.Book;
import Book.BookList;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-12-24
 * Time:10:51
 */
public class ReturnOpeartion implements IOPearation{
    @Override
    public void work(BookList bookList) {
        System.out.println("返还书籍!");
        Scanner scanner = new Scanner(System.in);

        //输入信息
        System.out.println("请输入归还图书的名字");
        String name = scanner.nextLine();

        int size = bookList.getUsedSize();
        for (int i = 0; i < size; i++) {
            // 判断这本书是否以及存在
            Book book1 = bookList.getBook(i);
            if (book1.getName().equals(name)){
                if (book1.isIsborrowed()){
                    book1.setIsborrowed(false);
                    System.out.println("归还成功!");
                    return;
            }
        }
    }
        System.out.println("归还失败!");
    }
}
